/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.ces4.produccion.client.utils;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.smartgwt.client.core.Function;
import com.smartgwt.client.types.ClickMaskMode;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 *
 * @author IAS
 */
public class Loader {

    private VLayout vLayout;
    private Canvas c;

    private Loader() {
        vLayout = new VLayout();
        vLayout.setAutoHeight();
        vLayout.setAutoWidth();
        Img i = new Img();
        i.setSrc(GWT.getModuleBaseURL() + "ajax-loader.gif");
        i.setWidth(32);
        i.setHeight(32);
        vLayout.addMember(i);
        vLayout.showClickMask(new Function() {

            @Override
            public void execute() {
            }
        }, ClickMaskMode.HARD, new Canvas[0]);

        vLayout.setTop((Window.getClientHeight() / 2) - 32);
        vLayout.setLeft((Window.getClientWidth() / 2) - 32);
        c = new Canvas();

        c.setWidth100();
        c.setHeight100();
        c.setBackgroundColor("#333333");
        c.setOpacity(60);
        c.bringToFront();
        vLayout.bringToFront();
    }

    public static void showLoader() {
        LoaderTestHolder.INSTANCE.c.show();
        LoaderTestHolder.INSTANCE.vLayout.show();
    }

    public static void hideLoader() {
        LoaderTestHolder.INSTANCE.c.hide();
        LoaderTestHolder.INSTANCE.vLayout.hide();
        LoaderTestHolder.INSTANCE.vLayout.hideClickMask();
    }

    private static class LoaderTestHolder {

        private static final Loader INSTANCE = new Loader();
    }
}
